<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head th:include="common/header"></head>
<body>

<div th:replace="common/fragment :: bbs_header"></div>

<div class="main layui-clear">

    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li><a href="/login">登入</a></li>
                <li class="layui-this">注册</li>
            </ul>
            <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form layui-form-pane">
                        <form method="post">
                            <div class="layui-form-item">
                                <label for="L_email" class="layui-form-label">邮箱</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_email" name="email" required lay-verify="email"
                                           autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">将会成为您唯一的登入名</div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_username" class="layui-form-label">昵称</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_username" name="name" required lay-verify="required"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_pass" class="layui-form-label">密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_pass" name="password" required lay-verify="required"
                                           autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_repass" class="layui-form-label">确认密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_repass" name="repass" required lay-verify="conform"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <button class="layui-btn" lay-filter="register" lay-submit>立即注册</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

<!-- 引入页脚 -->
<div th:replace="common/fragment :: bbs_footer"></div>

<!-- 引入js -->
<script th:src="@{/js/jquery-1.11.1.min.js}"></script>
<script th:src="@{/css/res/layui/lay/dest/layui.all.js}"></script>
<script th:src="@{/js/kits.js}"></script>

<script type="text/javascript">

    ;!function () {
        //初始化表单
        var form = layui.form;

        //验证表单
        form.verify({
            conform:function(value){//这里是验证两次输入是否一至
                var newPwd = $("form input[name=password]").val();
                $.logs.info(newPwd);
                if(newPwd != value) {
                    return "两次密码输入不一至!";
                }
            }
        });

        form.on('submit(register)', function (data) {

            $.logs.info(data.field);

            $.http.submitForm({
                url: "/userRegister",
                data: data.field,
                success: function (r) {
                    if (r && r.success) {
                        //注册成功跳转到登陆页面
                        $.prompt.alert(r.msg, "/login");
                    } else {
                        $.prompt.alert(r.msg, null);
                    }
                }
            });
            return false; //阻止表单跳转。因为使用ajax所以这里阻止表单的自动跳转
        });
    }();

</script>


</body>
</html>